#include "Log.h"
#include "Builder.h"
#include <boost/thread.hpp>

using namespace logger;

int run(LogPriority priority, const std::string& message)
{
	while (1)
	{
		CLOGF(priority, "%s", message.c_str());

		CLOGS(priority) << message;
		usleep(5000000);
	}

	return 0;
}

int main()
{
	LogOption option;
	option.priority = logger::kDebug | logger::kInfo | logger::kError;
	option.logger_ptr = LoggerPtr(new logger::OStreamLogger);
	option.formatter_ptr = FormatterPtr(new StringFormatter("[%D] [%T] [%P] %M"));
	option.start_on_create = true;

	LoggerPtr logger_ptr(new logger::OStreamLogger);

	get_log_dispatcher().add_logger("syslog", option);

	CLOGS(kDebug) << "test";

	int result = get_log_builder().build_from_file("log.json", "json");
	get_log_dispatcher().start_all();
	
	get_log_dispatcher().delete_logger("syslog");
	
	boost::thread thread1(boost::bind(&run, (LogPriority)kDebug, "thread1 test"));
	boost::thread thread2(boost::bind(&run, (LogPriority)kInfo, "thread2 test"));
	boost::thread thread3(boost::bind(&run, (LogPriority)kError, "thread3 test"));

	thread1.join();
	thread2.join();
	thread3.join();

	return 0;
}
